﻿using System;
using System.Globalization;

namespace JWXH.XH.utils
{
    public class TypeUtils
    {
        /// <summary>
        /// 从rgba的颜色中分解为四个数组的int类型  如 #FF00FF00  会返回  [255,0,255,0] 对应 argb
        /// </summary>
        /// <param name="strColor"></param>
        /// <returns></returns>
        public static int[] GetRGBAfromString(string strColor)
        {
            var finalStr = strColor.Replace("#", "");
            if(finalStr.Length < 8) throw new Exception("颜色长度不足8位，请传入形如: #FF00FF00");
            int[] ret = new int[4];
            ret[0] = int.Parse(finalStr.Substring(0, 2), NumberStyles.HexNumber);
            ret[1] = int.Parse(finalStr.Substring(2, 2), NumberStyles.HexNumber);
            ret[2] = int.Parse(finalStr.Substring(4, 2), NumberStyles.HexNumber);
            ret[3] = int.Parse(finalStr.Substring(6, 2), NumberStyles.HexNumber);

            return ret;
        }
    }
}